package com.tydic.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tydic.common.core.utils.StringUtils;
import com.tydic.common.mybatis.core.page.TableDataInfo;
import com.tydic.system.domain.SysDictType;
import com.tydic.system.domain.bo.QuerySysDictTypeBo;
import com.tydic.system.domain.vo.SysDictTypeVo;
import com.tydic.system.mapper.SysDictDataMapper;
import com.tydic.system.mapper.SysDictTypeMapper;
import com.tydic.system.service.ISysDictTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 字典 业务层处理
 *
 * @author Lion Li
 */
@RequiredArgsConstructor
@Service
public class SysDictTypeServiceImpl implements ISysDictTypeService {

    private final SysDictTypeMapper baseMapper;
    private final SysDictDataMapper dictDataMapper;


    @Override
    public TableDataInfo<SysDictTypeVo> queryPage(QuerySysDictTypeBo bo) {
        Page<SysDictTypeVo> page = baseMapper.selectVoPage(bo.build(), buildLambdaQueryWrapper(bo));
        return TableDataInfo.build(page);
    }

    @Override
    public SysDictTypeVo queryById(String id) {
        return baseMapper.selectVoById(id);
    }

    private LambdaQueryWrapper<SysDictType> buildLambdaQueryWrapper(QuerySysDictTypeBo bo) {
        LambdaQueryWrapper<SysDictType> lqw = Wrappers.lambdaQuery(SysDictType.class);
        lqw.like(StringUtils.isNotBlank(bo.getDictType()), SysDictType::getDictType, bo.getDictType());
        lqw.like(StringUtils.isNotBlank(bo.getDictType()), SysDictType::getDictName, bo.getDictName());
        lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SysDictType::getStatus, bo.getStatus());
        return lqw;
    }
}
